﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BizTalk.ESB.Extensions.Rules
{
    [Serializable]
    public class RulesStringFunctions
    {
        public String UpperCase(String Value)
        {
            if (String.IsNullOrEmpty(Value))
            {
                return Value;
            }
            else
            {
                return Value.ToUpper();
            }
        }

        public Boolean IsValidDate(String DateValue)
        {
            if (String.IsNullOrEmpty(DateValue))
            {
                return false;
            }
            else
            {
                try
                {
                    DateTime d = System.DateTime.Parse(DateValue);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }

        public Int32 GetStringLength(String Value)
        {
            if (String.IsNullOrEmpty(Value))
            {
                return 0;
            }
            else
            {
                return Value.Length;
            }
        }

        public Boolean StringContainsCharacters(String Value, String CharactersToCheck)
        {
            if (String.IsNullOrEmpty(Value) == false && String.IsNullOrEmpty(CharactersToCheck) == false)
            {
                Boolean found = false;
                foreach (Char c in CharactersToCheck.ToCharArray())
                {
                    if (Value.Contains(Convert.ToString(c)))
                    {
                        found = true;
                    }
                }
                return found;
            }
            else
            {
                return false;
            }
        }
    }
}
